<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.tjsinfo.tjsoa.system.vo.User"%>
<%@page import="com.tjsinfo.tjsoa.messageImportant.vo.MessageImportantMain"%>
<%@page import="com.tjsinfo.tjsoa.messageImportant.vo.MessageImportantIncept"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>"/>
		<title>粮油集团办公自动化协作平台</title>
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<link href="<%=basePath%>style/txlz7.css" rel="stylesheet" type="text/css" id="txlz7" />
		<style>
		.daohang {
		    background-image: url(<%=basePath%>images/ju.gif) !important;
		}
		</style>
		<link rel="stylesheet" type="text/css" href="<%=basePath%>ajaxFramework/ext-2.1/resources/css/ext-all.css" />
		<script type="text/javascript" src="<%=basePath%>ajaxFramework/ext-2.1/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="<%=basePath%>ajaxFramework/ext-2.1/ext-all.js"></script>
		<%
		User user = (User)session.getAttribute("user");
		List<MessageImportantMain> list = (List<MessageImportantMain>)request.getAttribute("list");
		int pagecount = 0;
		if(list.size() != 0){
			pagecount = list.size();
		}
	 %>

		<script language="JavaScript" type="text/javascript">//最大数据量
	 	window.onload = function(){
		initpage(1);
			var tb = new Ext.Toolbar(
				{
					height:25
				}
			);
		
		    tb.render('menu');
			tb.add(
		    {
		            text:'新增信息',
		            iconCls: 'daohang',
		        	handler: function(){
		        		location.href="<%=basePath %>messageImportant/insertMessage.jsp";
					}
		    }
		    );
		
		}
	 	
var total="<%=pagecount %>";
//每页的显示量
var pagesize="17";
//一共有多少页

var pagenum=Math.ceil(total/pagesize);
//生成导航
var nowpage = 1;
function initpage(nowpage){
	var pagenav='<a>共'+pagenum+'页,当前为'+nowpage+'页</a>,<a href="javaScript:goToPage(1);">第一页</a>,<a href="javaScript:up('+ nowpage+');">上一页</a> ';
	pagenav += '<select onchange="goToPage(this.value);">';
	for(i=1;i<=pagenum;i++){
		if(i==nowpage){
			pagenav += '<option value="'+i+'" selected="selected">'+i+'</option>';
		}else{
			pagenav += '<option value="'+i+'">'+i+'</option>';
		}
	}
	pagenav += '</select>';
	pagenav += '<a href="javaScript:down('+ nowpage+');">下一页</a>,<a href="javaScript:goToPage('+ pagenum+');">最后一页</a>';
	if(pagenum != 0){
		document.getElementById('page').innerHTML=pagenav;
	}
}
//翻页
var deletei = '';
function goToPage(page){
	var z = deletei.split(",");
	var start=(page-1)*pagesize;
	var max=page*pagesize;
	var bl = true;
	for(vs=0;vs<total;vs++){
		var obj=document.getElementById('item_' + vs);
		obj.style.display="none";
		bl = true;
	}
	if(max>total)max=total;
	for(v=start;v<max;v++){
		var obj=document.getElementById('item_' + v);
		for(var j = 0;j<z.length;j++){
			if(z[j] != '' && z[j] == v){
				bl=false;
			}
		}
		if(deletei == '')bl=true;
		if(bl)obj.style.display="block"; else obj.style.display="none";
	}
	initpage(page);
}
//上一页

function up(nowpage){
if(nowpage>1)goToPage((nowpage-1));
}
//下一页

function down(nowpage){
if(nowpage<pagenum)goToPage((nowpage+1));
}
		function init(){
			window.parent.frames.mainFrame.location.reload();
		}
		function selectOne(str){
			window.location.href="<%=basePath %>tjsinfo/tjsoa/messageImportant/selectMessage.do?id="+str;
		}
		
		function paixu(){
			Ext.MessageBox.show({
		        title: '提示框',
		        msg:'选择日期排序方式',
		        width: 300,
		        buttons: { ok: "升序", no:"降序",cancel:'关闭' },  
		        fn: function(btn, text) {
		       		if (btn == 'ok') {
		       			window.location.href = '<%=basePath%>tjsinfo/tjsoa/messageImportant/loginSendMain.do?order=asc';
		            }else if(btn == 'no'){
		       			window.location.href = '<%=basePath%>tjsinfo/tjsoa/messageImportant/loginSendMain.do?order=desc';
		            }
		        }
		    });
		}
</script>
	</head>

	<body>
		<div id="right" style="z-index: 19; height: 98%">
			<div id="menu" style="padding-top: 4px;"></div>
			<table width="100%" border="0" cellspacing="0" cellpadding="0"
				height="100%">
				<tr>
					<td width="100%" valign="top" height="100%">
						<div class="contab" style="height: 90%; width: 99%">
							<table class="p_06" width="100%" border="0" cellspacing="0"
								id="mytable">
								<tr align="center" />
								<tr>
									<th width="25%" style="text-align: center;">
										日期(<a href="javascript:paixu();">排序</a>)
									</th>
									<th width="25%" style="text-align: center;">
										接收人

									</th>
									<th width="25%" style="text-align: center;">
										内容
									</th>
									<th width="25%" style="text-align: center;">
										操作
									</th>
								</tr>
								<%
                    	int i = 0;
                    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    	for (MessageImportantMain main : list) {
                    	String id = main.getId().toString();
                    	String datetime = sdf.format(main.getDatetime());
                    	String receiveUsers = "";
               
                    	if(main.getInfo().length() > 25)
                    	{
                    		main.setInfo(main.getInfo().substring(0,25));
                    	}
                    	
                    	String s=main.getInfo();
                    	String s1="<br/>";
                    	String s2=s.replaceAll(s1,"&nbsp;");
                    	main.setInfo(s2);
                    	
                    	Object[] objects = main.getMessageImportantIncepts().toArray();
                    	for(int j = 0;j<objects.length;j++){
                    		MessageImportantIncept incept = (MessageImportantIncept)objects[j];
                    		receiveUsers += incept.getReceiveUsername()+",";
                    	}
                    	String receiveUsers1 = receiveUsers.substring(0,receiveUsers.length()-1);
						if(receiveUsers.substring(0,receiveUsers.length()-1).length()>15){
							receiveUsers = receiveUsers1.substring(0,15);
						}else{
							receiveUsers = receiveUsers1;
						}
						String info = main.getInfo();
						if(main.getInfo().length()>15){
							info = info.substring(0,15);
						}
					%>

								<tr onmouseover='this.className="trBgColor"'
									onmouseout='this.className=""' id="item_<%=i %>" onclick="selectOne('<%=id %>')">
									<td><%=datetime %></td>
									<td><a title="<%=receiveUsers1 %>"><%=receiveUsers %></a></td>
									<td>
										<a title="<%=main.getInfo()%>"><%=info%></a>
									</td>
									<td>
										<a
											href="<%=basePath %>tjsinfo/tjsoa/messageImportant/selectMessage.do?id=<%=id %>">查看</a>
									</td>
								</tr>
								<%
						i++;
						}
                     %>
								<tr align="center">
									<td colspan="7">
										<div class="pages" id="page">
										</div>
									</td>
								</tr>
							</table>
			</table>
		</div>
		<div class="insertGroup" id="shaodeng">
			<table width="478" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td height="24" align="left">
						<b>请求正在处理中,请稍候....</b>
					</td>
				</tr>
			</table>
		</div>
		<div id="blackdiv" class="black_overlays">
			<iframe
				style="width: 100%; height: 100%; filter: alpha(opacity = 0); -moz-opacity: 0"></iframe>
		</div>
	<script>
		for(vs=1;vs<total;vs++){
			var obj=document.getElementById('item_' + vs);
			obj.style.display="none";
			for(v=1;v<pagesize;v++){
				if(vs==v){
					var obj=document.getElementById('item_' + vs);
					obj.style.display="block";
				}
			}
		}
	</script>
	</body>
</html>
